package cn.credit.loan.controller;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
/**
 * 延期还款信息控制类
 * @author 
 *
 */
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.credit.loan.entity.Postpone;
import cn.credit.loan.service.postpone.PostponeService;
/**
 * 款期还款信息控制类
 * @author 
 *
 */
@Controller
public class PostponeController {
		//日志输出
		private Logger logger = Logger.getLogger(PostponeController.class);
		//注入
		@Autowired
		private PostponeService postponeSerivce;
		
		
		/**
		 * 款期还款信息查询
		 * @param postpone
		 * @param model
		 * @return
		 */
		@RequestMapping(value="/postponelist")
		@ResponseBody
		public Object getPostponeLists(Postpone postpone,
									   @RequestParam(value="pageNum",required=false,defaultValue="1")Integer pageNum,
									   ModelMap model){
			try {
				PageHelper.startPage(pageNum, 10);
				List<Postpone> postponelist=postponeSerivce.getPostponeList(postpone);
				PageInfo<Postpone> info=new PageInfo<Postpone>(postponelist);
				model.addAttribute("pageInfo", info);
				model.addAttribute("postponelist", postponelist);
				model.addAttribute("postpone", postpone);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return "";
			
		}
		/**
		 * 款期还款信息添加
		 * @param postpone
		 * @param model
		 * @return
		 */
		@RequestMapping("/postponeadd")
		public String getPostponeAdd(Postpone postpone,ModelMap model)
		{
			try {
				boolean postponeadd=postponeSerivce.getPostponeAdd(postpone);
				if(postponeadd)
				{
					model.addAttribute("postpone", postpone);
					return "PostponeAdd";
				}
						
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
			
		}
		/**
		 * 款期还款信息更新
		 * @param postpone
		 * @param model
		 * @return
		 */
		@RequestMapping("/postponeupdate")
		public String getPostponeUpdate(Postpone postpone,ModelMap model)
		{
			try {
				postpone.setLoanId(4);
				postpone.setPostponeCause("今天阿大多数");
				postpone.setBondsman("测试004");
				postpone.setBondsmanTele("1344356789");
				postpone.setBondsmanAddress("广州");
				postpone.setPostponeDate(new Date());
				postpone.setPostponeToday("9");
				postpone.setPostponeStag("4");
				postpone.setCheckType("未审批");
				boolean postponeadd=postponeSerivce.getPostponeUpdate(postpone);
				if(postponeadd)
				{
					model.addAttribute("postpone", postpone);
					return "PostponeUpdate";
				}
						
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
			
		}
		
		
		/**
		 * 款期还款信息删除
		 * @param postponeId
		 * @param model
		 * @return
		 */
		@RequestMapping("/postponedelete")
		public String getPostponeDelete(int postponeId,ModelMap model)
		{try {
			
			boolean postponedelete=postponeSerivce.getPostponeDelete(postponeId);
			if(postponedelete)
			{
				model.addAttribute("postponeId", postponeId);
				return "PostponeDelete";
			}
					
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
			
		}
}
